﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="grdEvent.ascx.cs" Inherits="GUESTSMANAGEMENT.View.Event.grdEvent" %>
<%@ Register assembly="Coolite.Ext.Web" namespace="Coolite.Ext.Web" tagprefix="ext" %>
<%@ Register Src="~/View/Event/frmEvent.ascx" TagName="gEvent" TagPrefix="GMEvent" %>
<%@ Register Src="~/View/Event/frmRelationship.ascx" TagName="relacaoEvent" TagPrefix="Relationship" %>
<%@ Register Src="~/View/Event/grdRelationship.ascx" TagName="relationGrid" TagPrefix="grdRelationship" %>

<ext:ScriptManagerProxy ID="ScriptManagerProxy" runat="server">
</ext:ScriptManagerProxy>

<script type="text/javascript">
    function alertMessage() {
        eventGridPanel = eval('<%=eventGridPanel.ClientID%>');
        if (eventGridPanel.hasSelection())
            return "Confirma Exclusão? <br> <b>" + eventGridPanel.getSelectionModel().getSelected().data.NMEVENT + "</b>";

    }

    var getEventId = function(grid, rowIndex, columnIndex, e) {
        var t = e.getTarget();
        var record = grid.getStore().getAt(rowIndex);
        var columnId = grid.getColumnModel().getColumnId(columnIndex);
        var columnValue = grid.getColumnModel().getDataIndex(2);
        var id = record.get(columnValue);
        document.getElementById("GMEvent_txt_idEvent").value = id;
    }
</script>

<ext:DesktopWindow ID="winGrdEvent" runat="server" Collapsible="true" Icon="World" Maximizable="false" Title="Eventos" Width="480" Height="325">
    <Body>
        <ext:Hidden ID="txt_idEvent" runat="server"></ext:Hidden>
        <ext:Store ID="eventStore" runat="server" OnRefreshData="Refresh" RefreshAfterSaving="Auto">
            <Reader>
                <ext:JsonReader>
                    <Fields>
                        <ext:RecordField Name="CDEVENT" />
                        <ext:RecordField Name="NMEVENT" />
                        <ext:RecordField Name="DTEVENT" Type="Date"/>
                        <ext:RecordField Name="DSEVENT" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store> 
        <ext:FitLayout ID="FitLayout1" runat="server">
            <ext:GridPanel ID="eventGridPanel" 
                runat="server"
                StoreID="eventStore"
                StripeRows="true"
                Width="250" 
                Height="290"
                AutoExpandColumn="eventName">
                <TopBar>
                    <ext:Toolbar ID="ToolBar1" runat="server">
                        <Items>
                            <ext:ToolbarButton ID="btnNewEvent" runat="server" Icon="WorldAdd">
                                <Listeners>
                                    <Click Handler="newEvent();" />
                                </Listeners>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipNewEvent" runat="server" Html="Novo Evento"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnEditEvent" runat="server" Icon="WorldEdit" Enabled="false">
                                <AjaxEvents>
                                    <Click OnEvent="EditEvent" >
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{eventGridPanel}.getSelectionModel().getSelected().data.CDEVENT" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipEditEvent" runat="server" Html="Editar Evento"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnRelEvent" runat="server" Icon="ApplicationFormAdd" Enabled="false">
                                <AjaxEvents>
                                    <Click OnEvent="SetListGuests" >
                                        <ExtraParams>
                                            <ext:Parameter Name="idEvento" Value="#{eventGridPanel}.getSelectionModel().getSelected().data.CDEVENT" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipRelEvent" runat="server" Html="Releção dos Promoters"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnGrdRelationship" runat="server" Icon="BookAddressesEdit" Enabled="false">
                                <AjaxEvents>
                                    <Click OnEvent="SetRelationShip" >
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{eventGridPanel}.getSelectionModel().getSelected().data.CDEVENT" Mode="Raw" />
                                        </ExtraParams>
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTip1" runat="server" Html="Editar quantidade de convites"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                            <ext:ToolbarButton ID="btnExcluirEvent" runat="server" Icon="WorldDelete" Enabled="false">                     
                                <AjaxEvents>
                                    <Click OnEvent="ConfirmDeleteEvent">                                        
                                        <Confirmation ConfirmRequest="true" 
                                                      Title="Alerta"                                                                                                  
                                                      BeforeConfirm="config.confirmation.message = alertMessage()"                                                       
                                        />
                                        <ExtraParams>
                                            <ext:Parameter Name="id" Value="#{eventGridPanel}.getSelectionModel().hasSelection() ? #{eventGridPanel}.getSelectionModel().getSelected().data.CDEVENT : -1" Mode="Raw" />
                                        </ExtraParams>                                        
                                    </Click>
                                </AjaxEvents>
                                <ToolTips>
                                    <ext:ToolTip ID="ToolTipDeleteEvent" runat="server" Html="Excluir Evento"></ext:ToolTip>
                                </ToolTips>
                            </ext:ToolbarButton>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:Column ColumnID="eventName" Header="Nome" Width="160" DataIndex="NMEVENT" Sortable="true" />
                        <ext:Column ColumnID="eventDate" Header="Data" Width="120" DataIndex="DTEVENT" Sortable="true" >
                            <Renderer Fn="Ext.util.Format.dateRenderer('d/M/Y')" />
                        </ext:Column>
                        <ext:Column ColumnID="eventCDEVENT" Hidden="true" DataIndex="CDEVENT" Fixed="false" MenuDisabled="true" Align="Center" />
                    </Columns>
                </ColumnModel>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionMode" runat="server">
                        <Listeners>
                            <RowSelect Handler="#{btnExcluirEvent}.enable(); #{btnEditEvent}.enable(); #{btnRelEvent}.enable(); #{btnGrdRelationship}.enable();" />                             
                            <RowDeselect Handler="if (!#{eventGridPanel}.hasSelection()) {#{btnExcluirEvent}.disable(); #{btnRelEvent}.disable(); #{btnGrdRelationship}.disable(); }" />                
                        </Listeners>                       
                    </ext:RowSelectionModel>
                </SelectionModel>
                <Listeners>
                    <CellDblClick />
                    <CellClick Fn="getEventId" />
                </Listeners>
                <AjaxEvents>
                    <CellDblClick OnEvent="EditEvent" Failure="Ext.MessageBox.alert('Erro Leitura Banco de Dados', 'Error ocorreu no Ajax Event!');">
                        <EventMask ShowMask="true" Msg="Carregando..." Target="CustomTarget" CustomTarget="={#{eventGridPanel}.body}" />
                        <ExtraParams>
                            <ext:Parameter Name="id" Value="#{eventGridPanel}.getSelectionModel().getSelected().data.CDEVENT" Mode="Raw" />
                        </ExtraParams>
                    </CellDblClick>
                </AjaxEvents>
                <LoadMask ShowMask="true" />
                <SaveMask ShowMask="true" />
                <BottomBar>
                    <ext:PagingToolBar ID="PagingToolBar" runat="server" PageSize="10" StoreID="eventStore" />
                </BottomBar>
            </ext:GridPanel>
        </ext:FitLayout>
        <GMEvent:gEvent ID="GMEvent" runat="server" />
        <Relationship:relacaoEvent ID="Relationship" runat="server" />
        <grdRelationship:relationGrid ID="grdRelationship" runat="server" />
    </Body>
</ext:DesktopWindow>
